/**
 * Created by zhu on 2016/2/14.
 */
$(function(){

init_delivery();
    $('#delivery_confirm').on('click', function () {
        $('#delivery').modal('hide');
        $.get(contextPath+"/seller/deliver/"+ $('#deliveryId').val(), function (data) {
            data = $.parseJSON(data);
            if(data.status == 0){
                init_delivery();
            }else{
                alert("修改失败");
            }
        })
    })
});

function init_delivery(){
    $.get(contextPath+"/seller/order/2",function(data){
        data = $.parseJSON(data);
        var tbody = $('#tbody');
        tbody.empty();
        $.each(data.list,function(i,item){
            var temp = ' <tr>'+
                '<td scope="row" style="vertical-align: middle;">' +
                '<img src="'+contextPath+item.goods.index_url+'" style="height: 140px;width: 140px" class="img-thumbnail">'+
                '<p>'+item.goods.name+'</p></td>'+
                '<td style="vertical-align: middle;"><p>单价：'+item.goods.price+'</p>' +
                '<p>数量：'+item.amount+'</p>' +
                '<p>总价：'+item.price+'</p></td>'+
                '<td style="vertical-align: middle;">微信号：'+item.fans.weixing+
                '<p>留言：'+item.note+'</p>' +
                '<p>地址：'+item.addresses.fansAddress+'</p>' +
                '<p>电话：'+item.addresses.phone+'</p></td>'+
                '</td>'+
                '<td style="vertical-align: middle;"><input type="hidden" id="myid" value="'+item.id+'">' +
                '<button type="button" class="btn btn-default deliveryBtn"  data-toggle="modal" data-target="#delivery">发货</button></td>'+
                '</tr>';
            tbody.append(temp);
        });
        $('.deliveryBtn').on('click', function () {
            $('#deliveryId').val($($(this).parent().find("input")[0]).val());
        })
    });
}